/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.util.LinkedList;
import javax.ejb.Singleton;
import javax.ejb.LocalBean;

/**
 *
 * @author Mickey
 * this is a linked list of all the users which is accessed for manipulation and used to write user info to the database
 */
@Singleton
@LocalBean
public class ListOfUsersBean extends LinkedList<User>{

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
/**
 * 
 * @param username the username entered in the login page
 * @param password the password entered in the login page
 * @return
 * this method checks if the user is typing in the correct password when loggin in
 */
    public User validateUser(String username, String password) {
        //UserBean validatee = new UserBean();
        //validatee.setUserID(username);
        //validatee.setPassword(password);
        for (User user: this) {
            if (user.getUserID().equals(username)) {
                return user;
            }
        }
        return null;
    }
    
    /**
     * 
     * @param username the username enetered in the login page
     * @return 
     * this method unlocks the user
     */
    public boolean unlockUser(String username){
        for(User user: this){
            if(user.getUserID().equals(username)){
                user.unLock();
                return true;
            } 
        }
        return false;
    }
}
